<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <title>sessionStroage</title>
</head>
<body>
    <!-- 存储内容会随着浏览器窗口关闭而消失 -->
    <br>
    <button onclick="saveData()">点我保存数据</button>
    <button onclick="readData()">点我读取数据</button>
    <button onclick="deleteData()">点我删除数据</button>
    <button onclick="clearData()">点我清除所有数据</button>

    <script type="text/javascript">
        let p = {name: "brx", age: "22"}

        function saveData(){
            sessionStorage.setItem("msg", "hello")
            sessionStorage.setItem("message", "123")
            sessionStorage.setItem("p1", JSON.stringify(p))
        }

        function readData(){
            console.log(sessionStorage.getItem("msg"))
            console.log(sessionStorage.getItem("message"))
            res = sessionStorage.getItem("p1")
            console.log(res)
        }

        function deleteData(){
            sessionStorage.removeItem("message")
        }

        function clearData(){
            sessionStorage.clear()
        }
    </script>
</body>
</html>